#include "switchbt.h"

SwitchBt::SwitchBt(int a , int b)
    : bwidth(a),bheigth(b)

{
    this->setCheckable(true);
}



void SwitchBt::paintEvent(QPaintEvent*)
{
    QPainter painter(this);
    painter.setRenderHint(QPainter::Antialiasing);
    this->drawBackGround(&painter);
    this->drawRound(&painter);
}

void SwitchBt::drawBackGround(QPainter* painter)
{
    if (this->isChecked())
    {
        painter->setBrush(QBrush(QColor(10, 77, 83)));
    }
    else
    {
        painter->setBrush(QBrush(QColor(98, 110, 120)));
    }
    painter->setPen(QPen(QColor(0,0,0,0)));
    painter->drawRoundedRect(0, 0, bwidth, bheigth, rp1,rp1 );
}

void SwitchBt::drawRound(QPainter* painter)
{
    painter->setPen(Qt::NoPen);
    if (this->isChecked())
    {
        QLinearGradient lineGradient(bwidth/15, bheigth/8, bheigth/1.3, bheigth/1.3);
        lineGradient.setColorAt(0, QColor(0, 251, 234));
        lineGradient.setColorAt(1, QColor(0, 146, 136));
        lineGradient.setSpread(QGradient::PadSpread);
        painter->setBrush(QBrush(lineGradient));
        painter->drawRoundedRect(bwidth/15,  bheigth/8, bheigth/1.3, bheigth/1.3, rp2, rp2);
    }
    else
    {
        painter->setBrush(QBrush(QColor(220, 222, 224)));
        painter->drawRoundedRect(bwidth-bwidth/15-bheigth/1.3, bheigth/8, bheigth/1.3, bheigth/1.3, rp2, rp2);
    }
}
